#pragma once
#include"Myhash.h"
namespace shuaiming_hash_bucket
{
	template<class K, class Hash = HashFunc<K >>
	class unordered_set
	{
		struct UnSetOfK
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};
	public:
		typedef typename shuaiming_hash_bucket::HashTable<K, const K, UnSetOfK, Hash>::Iterator iterator;
		typedef typename shuaiming_hash_bucket::HashTable< K, const K, UnSetOfK, Hash>::ConstIterator const_iterator;
		unordered_set() : _ht() {}
		// iterator
		iterator begin() { return _ht.Begin(); }
		iterator end() { return _ht.End(); }
		const_iterator begin() const { return _ht.Cbegin(); }
		const_iterator end() const { return _ht.Cend(); }
		// capacity
		size_t size() const { return _ht.Size(); }
		bool empty() const { return _ht.Empty(); }
		// modify
		pair<iterator, bool> insert(const K& key) { return _ht.Insert(key); }
		iterator erase(const K& key) { return _ht.Erase(key); }
		iterator find(const K& key) { return _ht.Find(key); }
		// bucket
		size_t bucket_count() { return _ht.BucketCount(); }
		size_t bucket_size(const K& key) { return _ht.BucketSize(key); }
	private:
		HashTable<K, const K, UnSetOfK, Hash> _ht;
	};
	void print(const unordered_set<int>& s)
	{
		auto it = s.begin();
		while (it != s.end())
		{
			//*it = 1;
			cout << *it << " ";
			++it;
		}
		cout << endl;

		for (auto e : s)
		{
			cout << e << " ";
		}
		cout << endl;
	}

	void test_set1()
	{
		int a[] = { 3,11,86,7,88,82,1,881,5,6,7,6 };
		unordered_set<int> s;
		for (auto e : a)
		{
			s.insert(e);
		}

		unordered_set<int>::iterator it = s.begin();
		while (it != s.end())
		{
			//*it = 1;
			cout << *it << " ";
			++it;
		}
		cout << endl;

		for (auto e : s)
		{
			cout << e << " ";
		}
		cout << endl;
		//cout << s.bucket_count() << endl;
		//cout << s.bucket_size(99999) << endl;
		//print(s);
		//for (auto& e : a)
		//	s.erase(e);
		auto a4 = s.erase(3);
		cout << *a4 << endl;;
		cout << endl;
		cout << s.bucket_count() << endl;
		cout << s.bucket_size(1) << endl;
	}
}
